package cn.disicn.controller;

import org.apache.commons.lang3.StringUtils;
import cn.disicn.common.Const;
import cn.disicn.common.ServerResponse;
import cn.disicn.model.AppSystemContact;
import cn.disicn.model.AppUser;
import cn.disicn.model.AppVersion;
import cn.disicn.model.BizJobs;
import cn.disicn.model.BizJobsAttachment;
import cn.disicn.model.BizJobsOrderSubmitResult;
import cn.disicn.model.BizJobsOrderSubmitResultAttachment;
import cn.disicn.model.SecPublishUser;
import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**
 * @author zjk
 * @date 2018年1月2日 上午9:35:14
 * @desc 页面访问
 */
public class IndexController extends Controller {

    private static final SecPublishUser secPublishuser = new SecPublishUser();
    private static final BizJobs bizJobs = new BizJobs();
    private static final BizJobsAttachment bizJobsattachment = new BizJobsAttachment();
    private static final AppUser appUser = new AppUser();
    private static final AppSystemContact appSystemcontact = new AppSystemContact();
    private static final AppVersion appVersion = new AppVersion();
    private static final BizJobsOrderSubmitResultAttachment bizJobsOrderSubmitResultAttachment = new BizJobsOrderSubmitResultAttachment();
    private static final BizJobsOrderSubmitResult bizJobsOrderSubmitResult = new BizJobsOrderSubmitResult();


    /**
     * @desc 主页面
     */
    public void index() {
        if (!getRequest().getRequestURI().equals("/")) {
            // 当登录后地址栏输入不存在的路径跳转到404页面
            renderError(404);
        }
        setAttr("secAdminUser", getSessionAttr(Const.UserType.CURRENT_ADMIN));
        render("index.jsp");
    }

    /**
     * @desc 登录
     */
    @Clear
    public void adminLogin() {
        render("adminLogin.jsp");
    }

    /**
     * @desc PC端用户
     */
    public void secUserList() {
        render("secUserList.jsp");
    }

    /**
     * @desc 审核实名认证页面
     */
    public void auditingRealName() {
        String id = getPara(0);
        if (!StringUtils.isBlank(id) && id.length() == 32) {
            setAttr("secuser", secPublishuser.getRealNameAuthInfo(id).getData());
        }
        render("auditingRealName.jsp");
    }

    /**
     * @desc 审核任务集合
     */
    public void auditingBizJobsList() {
        render("auditingBizJobsList.jsp");
    }

    /**
     * @desc 审核任务
     */
    public void bizJobsInfo() {
        String id = getPara(0);
        if (!StringUtils.isBlank(id) && id.length() == 32) {
            ServerResponse<Record> response = bizJobs.getBizJobsById(id);
            if (response.isSuccess()) {
                setAttr("bizJobs", response.getData());
                setAttr("bizJobsAttachment", bizJobsattachment
                        .getBizJobsAttachmentByJobsId(id).getData());
            }
        }
        render("bizJobsInfo.jsp");
    }

    /**
     * @desc 查看用户信息
     */
    public void secUserInfo() {
        String id = getPara(0);
        if (!StringUtils.isBlank(id) && id.length() == 32) {
            ServerResponse<SecPublishUser> response = secPublishuser
                    .findSecUserById(id);
            if (response.isSuccess()) {
                setAttr("secUser", response.getData());
            }
        }
        render("secUserInfo.jsp");
    }

    /**
     * @desc 添加管理员
     */
    public void addAdministrators() {
        render("addAdministrators.jsp");
    }

    /**
     * @desc 任务类型
     */
    public void bizJobsTypeList() {
        render("bizJobsTypeList.jsp");
    }

    /**
     * @desc app用户管理
     */
    public void appUserList() {
        render("appUserList.jsp");
    }

    /**
     * @desc app用户信息
     */
    public void appUserInfo() {
        String id = getPara(0);
        if (!StringUtils.isBlank(id) && id.length() == 32) {
            ServerResponse<AppUser> response = appUser.getAppUserInfoById(id);
            if (response.isSuccess()) {
                setAttr("appUser", response.getData());
            }
        }
        render("appUserInfo.jsp");
    }

    /**
     * @desc 充值记录信息
     */
    public void transactionRecord() {
        render("transactionRecord.jsp");
    }

    /**
     * @desc 职业类型
     */
    public void occupationalList() {
        render("occupationalList.jsp");
    }

    /**
     * @desc app内容帮助
     */
    public void appSystemHelpList() {
        render("appSystemHelpList.jsp");
    }

    /**
     * @desc 添加app内容帮助
     */
    public void addAppSystemHelp() {
        render("addAppSystemHelp.jsp");
    }

    /**
     * @desc app联系方式
     */
    public void appSystemContact() {
        render("appSystemContact.jsp");
    }

    /**
     * @desc 操作app联系方式
     */
    public void operationAppSystemContact() {
        String id = getPara(0);
        if (!StringUtils.isBlank(id) && id.length() == 32) {
            AppSystemContact appContact = appSystemcontact
                    .getAppSystemContactById(id);
            if (appContact != null) {
                setAttr("appContact", appContact);
            }
        }
        render("operationAppSystemContact.jsp");
    }

    /**
     * @desc app问题反馈
     */
    public void appFeedbackList() {
        render("appFeedbackList.jsp");
    }

    /**
     * @desc app版本
     */
    public void appVersionList() {
        render("appVersionList.jsp");
    }

    /**
     * @desc app版本操作
     */
    public void appVersion() {
        String id = getPara(0);
        if (!StringUtils.isBlank(id) && id.length() == 32) {
            AppVersion appV = appVersion.getAppVersionById(id);
            if (appVersion != null) {
                setAttr("appVersion", appV);
            }
        }
        render("appVersion.jsp");
    }

    public void refundApplication() {
        render("refundApplication.jsp");
    }

    /**
     * @desc 未审核完成的任务
     */
    public void bizJobsNoAuditingList() {
        render("bizJobsNoAuditingList.jsp");
    }

    /**
     * @desc 查看完成提交审核的任务
     */
    public void lookBizJobsSubmitResult() {
        String id = getPara(0);
        setAttr("bizJobsOrderSubmitResultAttachment",
                bizJobsOrderSubmitResultAttachment.getBizJobsOrderSubmitResultAttachmentByResultId(id));
        setAttr("bizJobsSubmitResult", bizJobsOrderSubmitResult.getBizJobsOrderSubmitResultById(id));
        render("lookBizJobsSubmitResult.jsp");
    }
}
